package c_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

//list集合遍历方式
public class ListForDemo03 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("蜘蛛精");
        list.add("至尊宝");
        list.add("至尊宝");
        list.add("牛夫人");

        //1.普通for循环
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.println(s);
        }

        //2.增强for循环
        for(String s : list){
            System.out.println(s);
        }

        //3.迭代器遍历
        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            String s = it.next();
            System.out.println(s);
        }

        //4.forEach方法
        list.forEach(s -> System.out.println(s));
    }
}
